<template>
  <div class="createPost-container">
    <el-form class="form-container" :model="form" :rules="rules" ref="refForm" label-width="120px">

      <el-form-item label="显示端:" prop="displayDevice">
        <el-select v-model="form.displayDevice" filterable placeholder="请选择显示端">
          <el-option v-for="item in consts.DEVICE_TYPE"
                     :key="item.value"
                     :label="item.title"
                     :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="充值教程类型:" prop="rechargeType">
        <el-select v-model="form.rechargeType" filterable placeholder="请选择充值教程类型">
          <el-option v-for="item in consts.RECHARGE_TYPE_NAMES"
                     :key="item.value"
                     :label="item.title"
                     :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="教程主题:" prop="theme">
        <el-input type="textarea" :rows="1" class="article-textarea" autosize placeholder="请输入内容"
                  v-model="form.theme">
        </el-input>
      </el-form-item>

      <el-form-item label="教程内容:" prop="content">
        <Tinymce :height=400 ref="editor" v-model="form.content"/>
        <!--<weditor ref="editor" v-model="form.content"></weditor>-->
      </el-form-item>

      <el-button v-loading="loading" style="margin-left: 10px;" type="primary"
                 @click="doSave({
                 action: 'saveForm',
                 form: {
                 name: 'refForm',
                 scrollToError: true
                 }})">确定
      </el-button>
    </el-form>
  </div>
</template>

<script>

  import {
    noticeRechargeHelpDetailApi as detailApi,
    noticeRechargeHelpSaveApi as saveApi
  } from '@/services/api/notice'
  import {form} from '@/build'
  // import weditor from "@/components/WEditor/index";
  import Tinymce from '@/components/Tinymce'

  export default {
    name: 'help-edit',
    components: {
      // weditor,
      Tinymce,
    },

    mixins: [form],

    props: ['id'],
    data() {
      return {
        form: {
          id: this.id,
          displayDevice: consts.ALL,
          rechargeType: undefined,
          theme: undefined,
          content: undefined
        },
        rules: {
          displayDevice: [
            {required: true, message: '显示端必须选择',},
          ],
          rechargeType: [
            {required: true, message: '充值教程类型必须选择',},
          ],
          theme: {required: true, message: '教程主题必须填写'},
          content: {required: true, message: '内容必须填写'},
        }
      }
    },
    mounted() {
      if (this.form.id) {
        this.bindGet(detailApi, 'form', {
          sendingData: 'form.id'
        })
        this.getAll();
      }

      this.bindSave(saveApi, 'saveForm', 'form', {
        afterSuccess: () => {
          this.$emit('on-success');
          if (!this.form.id) {
            this.$router.push({
              name: 'recharge-help-setting',
              query: {
                tab: 'one'
              }
            })
          }
        }
      });
    },
  }
</script>

<style lang="scss" scoped>
  .image {
    width: 100px;
    height: 100px;
  }
</style>
